package dataStructQueue;

public class MyQueue {

    static class Node{
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }

    public Node head;
    public Node last;

    //  入队列
    public void offer(int val){
        Node node = new Node(val);
        if(head == null){
            head = node;
            last = node;
        }else {
            last.next = node;
            last = node;
        }
    }

    //  出队列
    public int pool(){
        if(head == null){
            throw new RuntimeException(" 队列为空 ");
        }else {
            int ret = head.val;
            head = head.next;
            return ret;
        }
    }

    //  获取队首元素
    public int peek(){
        if(head == null){
            throw new RuntimeException(" 队列为空 ");
        }else {
            return head.val;
        }
    }




}
